// components/tree/tree.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model: Object,
    parent:Object,

  },

  /**
   * 组件的初始数据
   */
  data: {
    open: true,     //是否展开
    isBranch: false, //是否有子级

  },

  /**
   * 组件的方法列表
   */
  methods: {toggle: function (e) {
    console.log('-1------------',e);
    if (this.data.isBranch) {
      this.setData({
        open: !this.data.open,
      })
    }
    this.triggerEvent('toggle',e);
  },
    tapItem: function (e) {
      var that = this;
      console.log('-2------------',e);
      var itemid = e.currentTarget.dataset.id;
      console.log('组件里点击的id: ' + itemid);
      this.setData({
        isBranch:true
      })
      this.triggerEvent('tapitem', { id: itemid }, { bubbles: true, composed: true });
    }
  },
  ready: function (e) {
    //console.log('-3------------',e);

    console.log('**************',this.properties.model);
    console.log(this.properties.model.childForumCommentList)


    let isBranch = this.properties.model.childForumCommentList != null && this.properties.model.childForumCommentList.length>0;
   
    this.setData({ 
      isBranch: isBranch,
    });
  
},
})
